package com.gxa.j259.springcloud.f.hystrix.config;

import com.netflix.hystrix.HystrixInvokable;
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

/**
 * @author thinknovo
 * @version 1.0
 */
public class HystrixHook extends HystrixCommandExecutionHook {
    @Override
    public <T> void onStart(HystrixInvokable<T> commandInstance) {
        System.out.println(" 钩子函数  HystrixHook");
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        // 重新绑定一次所有请求数据
        RequestContextHolder.setRequestAttributes(requestAttributes, true);
        super.onStart(commandInstance);
    }
}
